
# 设置交叉编译器环境
export PATH := /opt/riscv64-linux-x86_64-20210512/bin:$(PATH)
export ARCH := riscv

TOPDIR := /home/ubuntu18/m4-openwrt
# 包含 OpenWRT 的规则文件
include $(TOPDIR)/rules.mk

PKG_NAME:=lvgl-demo
PKG_VERSION=v8.3.1
PKG_RELEASE:=1

# 包含 OpenWRT 的规则文件
include $(INCLUDE_DIR)/package.mk

# 定义包信息
define Package/$(PKG_NAME)
	SECTION:=zx
	CATEGORY:=zx
	SUBMENU:=ui
	TITLE:=lvgl ui
	DEPENDS:= +m4-mpp
endef

# 定义包描述
define Package/$(PKG_NAME)/description
	lvgl ui.
endef

# 准备构建目录
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

# 设置编译和链接选项
BUILD_CFLAGS := -O3 -I./ -I./lv_drivers -I$(STAGING_DIR)/usr/include
#TARGET_CFLAGS += -I./ -I./lv_drivers
BUILD_LIBS := -lmpp_ve -lmpp_base -lmpp_ge -lmpp_decoder \
				-lmedia_player -lopenmax -lopenmax_base -lmad -lasound \
				-lmpp_audio_decoder -lmpp_encoder -lm -lpthread

# 设置交叉编译器
TARGET_CC := riscv64-unknown-linux-gnu-gcc
TARGET_CXX := riscv64-unknown-linux-gnu-g++
TARGET_AR := riscv64-unknown-linux-gnu-ar
TARGET_STRIP := riscv64-unknown-linux-gnu-strip

# 传递编译和链接选项
MAKE_FLAGS += \
	CFLAGS="$(BUILD_CFLAGS)" \
	LDFLAGS="$(TARGET_LDFLAGS)" \
	LIBS="$(BUILD_LIBS)"

# 安装步骤
define Package/$(PKG_NAME)/install
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/build/bin/lvgl-demo $(1)/usr/sbin/lvgl-ui
	cp $(PKG_BUILD_DIR)/build/bin/lvgl-demo $(CURDIR)/mylvgl
endef

# 调用构建包
$(eval $(call BuildPackage,lvgl-demo))

